#coding:utf-8
from TBSpider import TBSpider
from Output import Output
import datetime
import os
import platform
from threading import Timer
import time

def task():
    spider = TBSpider("https://detail.tmall.com/item.htm?spm=a230r.1.14.4.2e788298tyQNHO&id=43751299764&cm_id=140105335569ed55e27b&abbucket=8&sku_properties=21845:37023;31889:107474")
    id = spider.getItemID()
    count = spider.getCount()
    print 'id:'+id+' count:'+count
    out = Output(id,count)
    out.outputdata()

count = 0
def loopfunc(msg,starttime):
    task()
    print 'start_time', starttime, 'now time', time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), ' message --> %s' % (msg)
    Timer(5, loopfunc, ('running', time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))).start()

Timer(5, loopfunc, ('running', time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))).start()
